home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / openpole.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  1KB  |  53 lines

  1.                                      // Chapter 5 - Program 3
  2. #include <iostream.h>
  3.  
  4. int area(int rec_height, int rec_width);
  5.  
  6. struct rectangle {
  7.    int height;
  8.    int width;
  9. };
  10.  
  11. struct pole {
  12.    int length;
  13.    int depth;
  14. };
  15.  
  16. int area(int rec_height, int rec_width)  //Area of a rectangle
  17. {
  18.    return rec_height * rec_width;
  19. }
  20.  
  21.  
  22. main()
  23. {
  24. rectangle box, square;
  25. pole flag_pole;
  26.  
  27.    box.height = 12;
  28.    box.width = 10;
  29.    square.height = square.width = 8;
  30.  
  31.    flag_pole.length = 50;
  32.    flag_pole.depth = 6;
  33.  
  34.    cout << "The area of the box is " << 
  35.                        area(box.height, box.width) << "\n";
  36.    cout << "The area of the square is " << 
  37.                        area(square.height, square.width) << "\n";
  38.    cout << "The funny area is " << 
  39.                        area(square.height, box.width) << "\n";
  40.    cout << "The bad area is " << 
  41.                        area(square.height, flag_pole.depth) << "\n";
  42. }
  43.  
  44.  
  45.  
  46.  
  47. // Result of execution
  48. //
  49. // The area of the box is 120
  50. // The area of the square is 64
  51. // The funny area is 80
  52. // The bad area is 48
  53.